<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />


<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="lib/daterangepicker/daterangepicker.css" /> 
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>订单列表</title>
<style type="text/css">
	/*.dropDown{min-width: 120px;}*/
	.s-state{min-width: 120px;}
	
	.s-state label{
		width: 100%;
		display: block;
		height: 30px;
		line-height: 30px;
		padding: 0 20px;
		min-width: 60px;
	}

	.fun-edit input{width: 80px;}

	.label{
		font-weight: 500;

	}
</style>
</head>
<body>
	<!-- <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> -->
<!--startprint-->
<div id="printcontent"></div>
<!--endprint-->
<div id="contenthtml">
<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> <a _href="welcome.html" class="fun-toindex" href="javascript:;">首页</a> <span class="c-gray en">&gt;</span> 订单管理 <span class="c-gray en">&gt;</span> 订单列表 <a class="btn btn-success radius r mr-20 reload" style="line-height:1.6em;margin-top:3px" href="javascript:;" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
	<span class="r" style="margin-top: -2px; box-sizing: border-box;">

		<li class="dropDown dropDown_hover"><a href="#" class="dropDown_A"><button class="btn" id="statebtn">订单状态</button></a>
			<ul class="dropDown-menu radius box-shadow s-state">
				<label><input name="state" type="checkbox" value="0" data-name="待支付">待支付</label>
				<label><input name="state" type="checkbox" value="10" data-name="待发货">待发货</label>
				<label><input name="state" type="checkbox" value="20" data-name="已发货">已发货</label>
				<label><input name="state" type="checkbox" value="30" data-name="已收货">已收货</label>
				<label><input name="state" type="checkbox" value="40" data-name="已删除">已删除</label>

				<label><input name="state" type="checkbox" value="43" data-name="已取消">已取消</label>

				<label><input name="state" type="checkbox" value="41" data-name="已过期">已过期</label>
				
				<label><input name="state" type="checkbox" value="55" data-name="部分退款">部分退款</label>


				<label><input name="state" type="checkbox" value="44" data-name="已关闭">已关闭</label>

				<label><input name="state" type="checkbox" value="50" data-name="退款中">退款中</label>

				<label><input name="state" type="checkbox" value="100" data-name="已完成">已完成</label>
			</ul>
		</li>

<!-- 		<li class="dropDown dropDown_hover" ><a href="#" class="dropDown_A"><button class="btn" id="activity" style="width: 100px;">参与活动</button></a>
			<ul class="dropDown-menu radius box-shadow s-state" style="width: 100px;">
				<label><input name="state2" type="checkbox" value="is_bespeak" data-name="预购">预购</label>

			</ul>
		</li> -->
		
		<div style="display:inline-block; width:380px; position:relative;">
			日期范围：
			<input name="time" type="text" id="date-range1" class="input-text datainp" style="width:300px">
			<i class="Hui-iconfont i-close" id="inputclear">&#xe706;</i>
		</div>	

		<span style="position:relative">
			<input type="text" name="k"  placeholder="订单编号/收货人名称/收货人手机号" style="width:200px" class="input-text">
			<i class="Hui-iconfont i-close" id="inputclear">&#xe706;</i>
		</span>

		<span style="position:relative">
			<input type="text" name="user_name"  placeholder="购买者名称/id" style="width:100px" class="input-text">
			<i class="Hui-iconfont i-close" id="inputclear">&#xe706;</i>
		</span>

		<span style="position:relative">
			<input type="text" name="goods_name"  placeholder="商品名称" style="width:100px" class="input-text">
			<i class="Hui-iconfont i-close" id="inputclear">&#xe706;</i>
		</span>

		<button id="search" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		
<!-- 		<li class="dropDown dropDown_hover"><a href="#" class="dropDown_A"><button  class="btn btn-success">导出EXCEL</button></a>
			<ul class="dropDown-menu radius box-shadow">
				<li id='exportorder'><a href="javascript:;">订单EXCEL</a></li>
				<li id='exportgoods'><a href="javascript:;">商品EXCEL</a></li>
			</ul>
		</li> -->

		<!-- <li class="dropDown dropDown_hover"><a href="#" class="dropDown_A"><button  class="btn btn-success"><i class="Hui-iconfont">&#xe652;</i>批量打印</button></a>
			<ul class="dropDown-menu radius box-shadow">
				<li class='fun-allprint' data-type="1"><a href="javascript:;">百世快递</a></li>
				<li class='fun-allprint' data-type="2"><a href="javascript:;">邮政快递</a></li>
			</ul>
		</li> -->

		<!-- <button id="fun-allprint" class="btn btn-success" data-type="2"><i class="Hui-iconfont">&#xe665;</i> 百事批量打印</button> -->
	</span>
</nav>

<div class="pd-10">
	
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort" id="categorylist">
			<thead>
				<tr class="text-c sort0">
					<th width="40" class="valueid"><input name="" type="checkbox" value=""></th>
					<th width="60" class="fun-sort2" data-name="order_id" data-flag="0">订单ID</th>
					<th width="150">订单编号</th>
					<th width="150">购买产品</th>
					<th width="100">购买者</th>
					<th width="80">联系电话</th>
					<th width="60">收货人</th>
					<th width="80">省市</th>
					<th width="80">备注</th>
					<th>地址</th>
					<th width="100" class="fun-sort2" data-name="order_time" data-flag="0">创建时间</th>
					<th width="120" class="fun-sort2" data-name="total_quan" data-flag="0">金额</th>
					<!-- <th width="120">运费</th> -->
					<th width="120">状态</th>
					<th width="40">操作</th>
				</tr>
			</thead>
			<tbody id="content_sp">
				
			</tbody>
		</table>
	</div>

	<div class="cl pd-5 bg-1 bk-gray mt-10" id="operation"> 
		<a href="javascript:;" class="btn btn-warning l mr-10 mt-5 radius fun-all" data-type="stop"><i class="Hui-iconfont">&#xe6de;</i> 批量关闭</a> 
		<a href="javascript:;" class="btn btn-success l mr-10 mt-5 radius fun-all" data-type="start"><i class="Hui-iconfont">&#xe603;</i> 批量开启</a> 
		<a href="javascript:;" class="btn btn-danger l mr-10 mt-5 radius fun-all" data-type="del"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		<!-- <a class="btn btn-primary radius mt-5 l mr-10" data-title="添加内容" href="javascript:;" onclick="_open('添加','product-category-add.html','50%','50%',false)" href="javascript:;">
			<i class="Hui-iconfont">&#xe600;</i> 添加
		</a> -->
		<span class="r pt-5"  style="line-height: 35px;" id="page"></span>
		<span class="r mr-10"  style="line-height: 40px;" id="dataall"></span>
		
	</div>


</div>
</div>
<!-- 模版 -->
<script id="test" type="text/html">
<% for (x in list) { %>
	<tr class="text-c va-m sort1" >
		<td class="valueid"><input name="" type="checkbox" value="<%=list[x].order_id%>"></td>
		<td class="text-l" >
			<a href="javascript:;" onClick="_open('订单详情','order-detail.html?oid=<%=list[x].order_id%>','90%','70%',true)" style="text-decoration: underline;">
				<%=list[x].order_id%>
			</a>
        </td>
        <%if(list[x].order_number==0){ %>
            <td class="text-l "><%=list[x].pay_order_number%></td>
        <%}else{ %>   
            <td class="text-l "><%=list[x].order_number%></td>
        <%}%>
		<td class="text-l"><%=list[x].goods_name%></td>
		<td class="fun-search" data-name="user_name" data-value="<%=list[x].user_name%>"><%=list[x].user_name%> (<%=list[x].uid%>)</td>
		<td class="fun-edit" data-classname="mobile">
			<input type="text" name="" value="<%=list[x].mobile%>" >
		</td>
		<td class="fun-edit" data-classname="receiver">
			<input type="text" name="" value="<%=list[x].receiver%>">
		</td>
		<td><%=list[x].province_name%> <%=list[x].city_name%></td>
		<td class="fun-edit" data-classname="remark">
			<input placeholder="备注" type="text" name="" value="<%=list[x].remark%>">
		</td>

		<td class="fun-edit" data-classname="address">
			<input type="text" name="" value="<%=list[x].address%>" style="width: auto;">
		</td>
		<td><%=list[x].order_time%></td>

		<td class="text-l fun-edit" data-classname="total_transport">
			<!-- 总价：<%=list[x].total_cost%><br> -->
			¥ <span><%=list[x].total_fee%></span><br>
			<!-- 运费：<input type="text" name="" value="<%=list[x].total_transport%>" style="width: 40px; padding: 2px"><br> -->
		</td>
	
		<td class="td-indexshow">
			<!-- 显示文字 -->
			<b><%=list[x].order_state_cn%></b><br>
			<%if(list[x].order_state==20 || list[x].order_state==30){ %>


				<a href="javascript:;" onClick="_open('订单详情','order-detail.html?oid=<%=list[x].order_id%>','90%','70%',true)" style="text-decoration: underline;">
					查看详情
				</a>
			
			<%}else if(list[x].order_state==10 || list[x].order_state==52){ %>
				
				<span class="label label-success radius" data-flag="5" style="cursor: pointer;" onClick="_open('发货','order-trans-add.html?order_state=<%=list[x].order_state%>&oid=<%=list[x].order_id%>','80%','70%',false)">发货</span>

			<%}else if(list[x].order_state==50){%>
				<%=list[x].cancel_reason%><br>
			<%}%>
		</td>
		

		<td class="td-manage f-18">
 			<a style="text-decoration:none" class="label label-warning radius" onClick="_open('评论列表','order-evaluate.html?orderid=<%=list[x].order_id%>','90%','90%',false)" href="javascript:;" title="评论订单"><i class="Hui-iconfont">&#xe622;</i>评论</a> 
		</td>
	</tr>

<%}%>
</script>


<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/template-native.js"></script> 
<script type="text/javascript" src="js/s.js"></script> 
<!-- <script language="javascript" src="js/LodopFuncs.js"></script> -->

<script type="text/javascript" src="lib/laypage/laypage.js"></script> 
<script type="text/javascript" src="lib/daterangepicker/moment.min.js"></script> 
<script type="text/javascript" src="lib/daterangepicker/jquery.daterangepicker.js"></script>
<script src="/Manage/js/lazyload.min.js"></script>
<script type="text/javascript">
var API=API_ORDERLIST;
var kk=API_ORDERLIST;
var orderby='';
var search='';


var uid=getUrlParam('uid');//用户详情查询使用
if(uid!==null && uid!==undefined){
	API=API+'?uid='+uid;
	// $("nav").hide();
 //    $("#operation").hide();
}

loaddata(API,'',true);
$('#date-range1').dateRangePicker({
	startOfWeek: 'monday',
	separator : ' 至 ',
	format: 'YYYY-MM-DD HH:mm',
	autoClose: true,
	time: {
		enabled: true
	},
	defaultTime: moment().startOf('day').toDate(),
	defaultEndTime: moment().endOf('day').toDate()
});


var print_num=0;
var isshow=true;
// 批量打印的单个循环
function doPrint(id,type,obj) { 
	var eidturl=API_MIANDAN+"?oid="+id+'&type='+type;
	if(type==1){
		var text="百世快递包裹"
	}else{
		var text="邮政快递包裹"
	}
	$.getJSON(eidturl,function(data){
	    // if(!checkStatus(data)) return;//判断登录
	    
	    if(data.status==0){
	        // layer.msg("数据加载错误", {icon:2,time:1000});
	    }else{
			// LODOP=getLodop();         
			console.log("print")
			print_num++;
   			LODOP.PRINT_INIT("");
	        LODOP.ADD_PRINT_HTM(0,0,"100%","100%",data.datas.PrintTemplate);
	        
	        LODOP.PRINT(); 	
	    	
	        obj.closest("tr").find("td.td-indexshow").html('<b>已发货</b><br>'+text+'<br>'+data.datas.Order.LogisticCode)
	    }
	    
	})
}

// 批量打印
$(document).on('click','li.fun-allprint',function(){

	
	LODOP=getLodop(); 
	console.log(isshow)

	if(isshow){
		layer.load();
		print_num=0     
		var type=$(this).data("type");
		if(type==1){
			var name="百世"
		}else{
			var name="邮政"
		}
		var allnum=$("#content_sp .valueid input[type='checkbox']:checked").length;
		if($("#content_sp .valueid input[type='checkbox']:checked").length<1){
			layer.closeAll();
	        layer.msg('请选择要操作的内容!',{icon:2,time:2000});
	    }else{
	        var ids="";
	        
	        $.ajaxSettings.async = false;

	        $("#content_sp .valueid input[type='checkbox']:checked").each(function(e){
	        	var obj=$(this);
	            ids=ids+$(this).val()+",";
	            doPrint($(this).val(),type,obj);
	        })
	        
	        var text="你选中了"+allnum+"张，打印了"+print_num+"张";
	        layer.closeAll();
	        layer.msg(text,{icon:1,time:3000});

	        console.log(ids)
	    }
	}else{

		layer.msg("尚未安装打印插件",{icon:2,time:3000});
		
	}
		
	
	
	
	
})


$(document).on('click','a.fun-print',function(){
	var oid=$(this).data("oid");
	var type=$(this).data("type");
	var eidturl=API_MIANDAN+"?oid="+oid+'&type='+type;
	var that=$(this);	
	if(type==1){
		var text="<b>待收货</b><br>百世快递包裹<br>";
	}else{
		var text="<b>待收货</b><br>邮政快递包裹<br>";
	}
	$.getJSON(eidturl,function(data){
	    if(!checkStatus(data)) return;//判断登录

	    if(data.datas==''){
	        layer.msg("数据加载错误", {icon:2,time:1000});
	    }else{
	    	// that.parent().prev().html(text+data.datas.Order.LogisticCode)
	    	that.parent().prev().html("待收货")

	        
	        $("#printcontent").html(data.datas.PrintTemplate);
	        $("#contenthtml").hide();
	        window.print();
	        $("#contenthtml").show();
	        $("#printcontent").empty();

	    }
	    
	})
})

// 退款
$(document).on('click','span.fun-refund',function(){
	var flag=$(this).data("flag");
	var oid=$(this).data("orderid");
	console.log(oid);
	var that=$(this);
	if(flag==1){
		layer.confirm('退款后,券和运费将打到用户账户?',function(index){
			layer.close(index);
		console.log("同意")
	        
	        $.post(API_ORDERLIST,{
	        	oid:oid,
	        	type:'refund',
	        },function(data){
	        	// data=eval("( "+data+" )");
	        	if(!checkStatus(data)) return;
	        	
	        	that.parent().html("已同意√")

			    
	        },'json')
	    })
	}else if(flag==2){
		layer.use('extend/layer.ext.js', function(){
			layer.prompt({
		        title:'拒绝理由',
		    },function(val, index){
		        layer.close(index);
		console.log("处理不同意")

		        $.post(API_ORDERLIST,{
		        	oid:oid,
	        		type:'norefund',
		        },function(data){
		        	if(!checkStatus(data)) return;
		        	that.parent().html("已拒绝×")
		        },'json')
		    })
		})
	}
	
})

	$(document).on('click','#search',function(){
		// if(kk.indexOf('?') >= 0){
	 //        kk=kk+"&";
	 //    }else{
	 //    }
	    kk=API+"?";

	    // 订单状态
		var state='';
		var name='状态：';
		$("input[name='state']:checked").each(function(){ 		
			state += $(this).val()+',';
			name+=$(this).data("name")+','; 		
		})
		$("#statebtn").html(name);

		// 参与活动
		var state2='';
		var name2='活动：';
		$("input[name='state2']:checked").each(function(){ 		
			state2 += $(this).val()+'=1&';
			name2+=$(this).data("name")+','; 		
		})
		$("#activity").html(name2);

		var param=[
			'k='+encodeURI(document.querySelector('input[name=k]').value),
			'user_name='+encodeURI(document.querySelector('input[name=user_name]').value),			
			'goods_name='+encodeURI(document.querySelector('input[name=goods_name]').value),			
			'state='+state,
			'time='+document.querySelector('input[name=time]').value,
			// state2,
		];

		search=param.join('&');
	    kk=kk+orderby+search;
		loaddata(kk,1);

	})

	$(document).on('click','#exportorder',function(){
		var state='';
		$("input[name='state']:checked").each(function(){ 		
			state += $(this).val()+',';		
		})

		// 参与活动
		var state2='';
		$("input[name='state2']:checked").each(function(){ 		
			state2 += $(this).val()+'=1&';
		})

		var param=[
			'k='+encodeURI(document.querySelector('input[name=k]').value),
			'goods_name='+encodeURI(document.querySelector('input[name=goods_name]').value),
			'user_name='+encodeURI(document.querySelector('input[name=user_name]').value),			
			'state='+state,
			'time='+document.querySelector('input[name=time]').value,
			state2,
		];
		param=param.join('&');
		window.open(API_EXPORT_ORDER+'?'+param+orderby);
		console.log(API_EXPORT_ORDER+'?'+param+orderby)
	})

	$(document).on('click','#exportgoods',function(){
		var state='';
		$("input[name='state']:checked").each(function(){ 		
			state += $(this).val()+',';		
		})
		// 参与活动
		var state2='';
		$("input[name='state2']:checked").each(function(){ 		
			state2 += $(this).val()+'=1&';
		})
		var param=[
			'k='+encodeURI(document.querySelector('input[name=k]').value),
			'user_name='+encodeURI(document.querySelector('input[name=user_name]').value),
			'goods_name='+encodeURI(document.querySelector('input[name=goods_name]').value),			
			'state='+state,
			'time='+document.querySelector('input[name=time]').value,
			state2,
		];
		param=param.join('&');
		window.open(API_EXPORT_ORDERGOODS+'?'+param+orderby);
		console.log(API_EXPORT_ORDERGOODS+'?'+param+orderby)
	})

</script>

</body>
</html>